#include <iostream>
#include <vector>
#include <cstdio> 
#include <queue>
#include <cstring>

#define in read()
#define fi first
#define se second
#define pb push_back

using namespace std;

typedef long long ll;
typedef double db;
typedef vector < int >  vec;
typedef pair < int , int > pii;

int read() {
  int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
  while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 1e5 + 10;

int n,m,K;
ll ans = 1e18,dis[N];
bool vis[N];
vector < pii > G[N];
vec pot;

ll dijk(int s,int t) {
    priority_queue < pii , vector < pii > , greater<pii> > q; memset(dis,0x3f,sizeof dis); dis[s] = 0; q.push({dis[s],s});
    memset(vis,0,sizeof vis);
    while(!q.empty()) {
	int x = q.top().se; q.pop(); if(vis[x]) continue; vis[x] = true;
	if(x == t) return dis[x];
	for(auto d : G[x]) {
	    int y = d.fi,w = d.se;
	    if(dis[y] > dis[x] + w) dis[y] = dis[x] + w,q.push({dis[y],y});
	}
    } return 1e18;
}

int main() {
    for(int T = in;T;T--) {
	n = in,m = in,K = in; for(int i = 1;i <= n;i++) vector < pii > ().swap(G[i]); ans = 1e18;
	for(int i = 1,x,y,z;i <= m;i++) x = in,y = in,z = in,G[x].pb({y,z});
	vec().swap(pot); for(int i = 1;i <= K;i++) pot.pb(in);
	vec lpot;
	for(int bit = 0;bit < 19;bit++) {
	    vector < pii >().swap(G[0]); for(auto x : lpot) G[x].pop_back(); vec().swap(lpot);
	    for(int x : pot) if(x >> bit & 1) lpot.pb(x),G[x].pb({n + 1,0}); else G[0].pb({x,0});
	    ans = min(ans,dijk(0,n + 1));
	}
	vec().swap(lpot);
	for(int bit = 0;bit < 19;bit++) {
	    vector < pii >().swap(G[0]); for(auto x : lpot) G[x].pop_back(); vec().swap(lpot);
	    for(int x : pot) if(!(x >> bit & 1)) lpot.pb(x),G[x].pb({n + 1,0}); else G[0].pb({x,0});
	    ans = min(ans,dijk(0,n + 1));
	}
	printf("%lld\n",ans);
    } return 0;
} 
